package solutions.contest.week272;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/contest/weekly-contest-272/problems/number-of-smooth-descent-periods-of-a-stock/">2110.股票平滑下跌阶段的数目</a>
 */
public class Solution2110 extends BaseSolution {

    public long getDescentPeriods(int[] prices) {
        long result = 0;
        int c = 1, p = 1, len = prices.length;
        while (p < len) {
            if (prices[p - 1] - prices[p] == 1) {
                c++;
            } else {
                result += ((long) (c + 1)) * c / 2;
                c = 1;
            }
            p++;
        }
        result += ((long) (c + 1)) * c / 2;
        return result;
    }

    public static void main(String[] args) {
        Solution2110 solution = new Solution2110();
        long r = solution.getDescentPeriods(new int[]
                        {8,6,7,7}
                );
        System.out.println(r);
    }
}